package com.itheima.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itheima.pojo.CmsSubject;
import com.itheima.pojo.UmsRole;
import com.itheima.vo.PageResultVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CmsSubjectService {

    @DubboReference
    private CmsSubjectApi cmsSubjectApi;

    /**
     * 获取全部商品专题
     */
    public List<CmsSubject> listAll() {
        return cmsSubjectApi.listAll();
    }

    /**
     * 根据专题名称分页获取商品专题
     */
    public PageResultVo<CmsSubject> list(Integer pageNum, Integer pageSize, String keyword) {

        IPage<CmsSubject> page = cmsSubjectApi.list(pageNum,pageSize,keyword);

        PageResultVo<CmsSubject> pageResultVo = new PageResultVo<>();
        pageResultVo.setList(page.getRecords());
        pageResultVo.setPageNum((int) page.getCurrent());
        pageResultVo.setPageSize((int) page.getSize());
        pageResultVo.setTotal((int) page.getTotal());
        pageResultVo.setTotalPages((int) page.getPages());

        return pageResultVo;

    }
}
